<template>
  <div class="app-container fxgkView">
    <el-form ref="form" :model="form" :rules="rules">
      <BorderView title="风险管控" />
      <el-descriptions class="margin-top" :column="3" border>
        <el-descriptions-item
          label="风险管控*"
          label-style="width:100px;text-align:center"
          :span="3"
          label-class-name="labelBg"
        >
          <el-form-item prop="fxdjList">
            <el-checkbox-group v-model="form.fxdjList">
              <el-row>
                <el-col
                  v-for="(item, index) in dict.type.fxdj"
                  :key="index"
                  :span="24"
                >
                  <el-checkbox :label="item.value">
                    {{ item.label }}
                  </el-checkbox>
                </el-col>
              </el-row>
            </el-checkbox-group>
          </el-form-item>
        </el-descriptions-item>
      </el-descriptions>
    </el-form>
    <div
      slot="footer"
      class="dialog-footer"
      style="text-align: right; margin-top: 20px"
    >
      <el-button @click="cancel">重置</el-button>
      <el-button :loading="buttonLoading" type="primary" @click="submitForm"
        >下一步</el-button
      >
    </div>
  </div>
</template>
<script>
import { getUser, updateUser } from "@/api/user/userInfo";
import BorderView from "@/views/components/BorderTitleView/index.vue";
export default {
  dicts: ["fxdj", "jntc"],
  components: {
    BorderView,
  },
  props: {
    sjskId: {
      type: String,
    },
  },
  data() {
    return {
      // 按钮loading
      buttonLoading: false,
      // 表单参数
      form: {
        fxdjList: [],
      },
      // 表单校验

      rules: {
        fxdjList: [
          { required: true, message: "风险等级不能为空", trigger: "change" },
        ],
      },
    };
  },
  watch: {
    sjskId: {
      immediate: true,
      handler(newV) {
        if (newV) {
          getUser(newV).then((res) => {
            if (res.data) {
              this.form = res.data;
            } else {
              this.reset();
            }
          });
        }
      },
    },
  },
  methods: {
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          this.buttonLoading = true;
          updateUser(this.form)
            .then((response) => {
              this.$modal.msgSuccess("更新成功");
              this.$emit("goto-next", 6);
            })
            .finally(() => {
              this.buttonLoading = false;
            });
        }
      });
    },
    // 取消按钮
    cancel() {
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        fxdjList: [],
      };
      this.resetForm("form");
    },
  },
};
</script>
<style>
.labelBg {
  background: rgb(241, 243, 244) !important;
}
</style>
<style scoped>
.fxgkView /deep/.el-descriptions--small.is-bordered .contentBg {
  padding: 0 !important;
}
.fxgkView .el-input__wrapper {
  border: none !important;
  box-shadow: none !important;
  padding: 0px;
}
.fxgkView /deep/ .el-input__inner {
  border: none !important;
}
.fxgkView /deep/ .el-textarea__inner {
  border: none !important;
}
.fxgkView /deep/ .el-form-item {
  margin-bottom: 0;
}
</style>
